﻿/**
@file
    ServiceFiles.cs
@brief
    Copyright 2009 Creative Crew. All rights reserved.
@author
    William Chang
@version
    0.1
@date
    - Created: 2009-04-05
    - Modified: 2009-04-05
    .
@note
    References:
    - General:
        - http://encosia.com/2008/03/27/using-jquery-to-consume-aspnet-json-web-services/
        - http://www.asp.net/learn/ajax/tutorial-03-cs.aspx
        - http://www.dev102.com/2008/04/30/call-aspnet-webmethod-from-jquery/
        .
    .
*/

using System;
using System.Web.Services;

namespace ent {

/// <summary>Class ServiceLists extends ServiceCommon</summary>
[System.Web.Script.Services.ScriptService()]
public class ServiceFiles : ServiceCommon {
    /// <summary>Default constructor.</summary>
    public ServiceFiles() {}
    /// <summary>Get files.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public String getFiles() {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return String.Empty;}

        TableFiles t1 = new TableFiles();
        return DatabaseCommon.toJson(t1.getFiles(TableFiles.getColumnsRelevantFiles()));
    }
    /// <summary>Get recent files.</summary>
    /// <returns>A System.Data.DataTable instance containing the matching rows.</returns>
    public System.Data.DataTable getFilesRecent(int itemsLimit, System.Web.SessionState.HttpSessionState userSession) {
        TableFiles t1 = new TableFiles();
        System.Collections.Hashtable p1 = new System.Collections.Hashtable();

        p1.Add(TableFiles.TBL__files__file_uploader_user_id, Session[ApplicationCommon.SESSION__user_id].ToString());
        p1.Add("limit", itemsLimit);
        return t1.getContentsRecent(p1);
    }
    /// <summary>Get file filter extensions.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public String getFileFilterExtensions() {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return String.Empty;}

        TableFiles t1 = new TableFiles();
        return DatabaseCommon.toJson(t1.getFileFilterExtensions(TableFiles.getColumnsRelevantFileFilterExtensions()));
    }
    /// <summary>Get trashed files.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public String getFilesTrashed() {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return String.Empty;}

        TableFiles t1 = new TableFiles();
        return DatabaseCommon.toJson(t1.getFilesTrashed(TableFiles.getColumnsRelevantFiles()));
    }
    /// <summary>Get trashed file filter extensions.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public String getFileFilterExtensionsTrashed() {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return String.Empty;}

        TableFiles t1 = new TableFiles();
        return DatabaseCommon.toJson(t1.getFileFilterExtensionsTrashed(TableFiles.getColumnsRelevantFileFilterExtensions()));
    }
    /// <summary>Remove file (permanent).</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool removeFile(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.removeFile(intId);
    }
    /// <summary>Remove file filter extension (permanent).</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool removeFileFilterExtension(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.removeFileFilterExtension(intId);
    }
    /// <summary>Restore trashed file.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool restoreFile(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.restoreFile(intId);
    }
    /// <summary>Restore trashed file filter extension.</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool restoreFileFilterExtension(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.restoreFileFilterExtension(intId);
    }
    /// <summary>Trash file (impermanent).</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool trashFile(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.trashFile(intId);
    }
    /// <summary>Trash file filter extension (impermanent).</summary>
    /// <remarks>User must have authenticate session to proceed.</remarks>
    [System.Web.Services.WebMethod(EnableSession = true)]
    public bool trashFileFilterExtension(int intId) {
        // Authenticate.
        if(!ApplicationCommon.isValidSession(Session)) {return false;}

        TableFiles t1 = new TableFiles();
        return t1.trashFileFilterExtension(intId);
    }
}

} // END namespace ent